<template>
	<view class="content">
		<image style="width: 100%; height: 100%" :src="signUrl">
		</image>
		<view class="text-area">
			<text class="title" @click="goSign">去签名</text>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { postAttachmentTempUpload } from "@/utils/upload";
	import { baseUrl } from "@/utils/httpInterceptor";
	import { getSign } from "../user/api";
	import { Toast } from "@/utils/uniHooks/toast";
	import { ref, onMounted } from "vue";
	import { onLoad, onUnload } from "@dcloudio/uni-app";

	let signUrl = ref("");

	const setUrl = async() => {
		console.log("ABC");
		getSign().then(res => {
			if (res?.data?.attachmentUrl) {
				signUrl.value = `${baseUrl}${res.data.attachmentPath}`;
				console.log("signUrl.value = " + signUrl.value );
			}
		});
	}
	
	onMounted(() =>{
		setUrl();
	});
	
	onLoad(() =>{
		// 监听生成签字的图片地址
		uni.$on('q-sign',img =>{
			console.log('img',img);
			postAttachmentTempUpload(img, `${baseUrl}/organization/user/sign/upload`).then(res =>{
				if (res.code === "0") {
					Toast("修改签名成功");
				} else {
					Toast(res.msg);
				}
			});
		})
	});
	
	onUnload(()=>{
		//移除监听事件
		uni.$off('q-sign') 
	});
	
	const goSign = async() => {
		uni.navigateTo({
			url:'/uni_modules/q-sign/pages/q-sign'
		})
	};
	
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
